package com.tjsinfo.tjsoa.efile.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import org.hibernate.Session;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Order;

import com.tjsinfo.tjsoa.address.common.TAddresslistCommon;
import com.tjsinfo.tjsoa.efile.vo.Efile;
import com.tjsinfo.tjsoa.reminded.vo.TSystemReminded;



/**
 * A data access object (DAO) providing persistence and search support for Efile
 * entities. Transaction control of the save(), update() and delete() operations
 * can directly support Spring container-managed transactions or they can be
 * augmented to handle user-managed Spring transactions. Each of these methods
 * provides additional information for how to configure it for the desired type
 * of transaction control.
 * 
 * @see com.tjsinfo.system.efile.Efile
 * @author MyEclipse Persistence Tools
 */

public class EfileDao extends HibernateDaoSupport implements IEfileDao {
	private static final Log log = LogFactory.getLog(EfileDao.class);

	/* (non-Javadoc)
	 * @see com.tjsinfo.system.efile.EfileDao#save(com.tjsinfo.system.efile.Efile)
	 */
	public void save(Efile transientInstance) {
		log.debug("saving Efile instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}
	/* (�ϴ��ļ�������ɾ��)
	 * @see com.tjsinfo.system.user.UsersDao#delete(com.tjsinfo.system.user.Users)
	 */
//	public void delete(String propertyName, Object value) {
//		log.debug("deleting Efile instance");
//		try {
//			String queryString = "delete Efile where "+propertyName+" = "+value;
//			getHibernateTemplate().delete(value);
//			log.debug("delete successful");
//		} catch (RuntimeException re) {
//			log.error("delete failed", re);
//			throw re;
//		}
//	}
	public void delete(Efile persistentInstance) {
		log.debug("deleting Efile instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}
	/* (non-Javadoc)
	 * @see com.tjsinfo.system.efile.EfileDao#findById(java.lang.Integer)
	 */
	public Efile findById(java.lang.Integer id) {
		log.debug("getting Efile instance with id: " + id);
		try {
			Efile instance = (Efile) getHibernateTemplate()
					.get("com.tjsinfo.tjsoa.efile.vo.Efile", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.system.efile.EfileDao#findByProperty(java.lang.String, java.lang.Object)
	 */
	public List<Efile> findByProperty(String propertyName, Object value) {
		log.debug("finding Efile instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from Efile as model where model."
					+ propertyName + "= ? order by id desc";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
	   public List findByTwoRow(Efile efile) {
			try {
				String queryString = "from Efile as model where model.cid = ? and model.remark = ?";
				String[] param={efile.getCid(),efile.getRemark()};
				return getHibernateTemplate().find(queryString, param);
			} catch (RuntimeException re) {
				log.error("find by property name failed", re);
				throw re;
			}
		}
	public List findByLimit(int begin, int number, String property, Object value) {
		// TODO Auto-generated method stub
		log.debug("finding Efile instance with property: " + begin
				+ ", value: " + number);
		try {
			Criteria criteria = getSession().createCriteria(Efile.class);
			criteria.addOrder(Order.desc("id"));
			criteria.add(Expression.eq("cid", value));
			criteria.setFirstResult(begin);
			criteria.setMaxResults(number);
			return criteria.list();
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}
}